/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kohan.battleship;

import java.util.Scanner;

/**
 *
 * @author STano
 */
public class User extends Player{

    private final Scanner in;
    
    public User(String name) {
        super(name);
        this.in  = new Scanner(System.in);
    }

    public User(String name, String color) {
        super(name, color);
        this.in  = new Scanner(System.in);
    }

    @Override
    public boolean addShip(int x, int y) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    

    @Override
    public int[] setCoordinates() {
        int[] coordinates = new int[2];
        
        System.out.println("Set x:");
        coordinates[0] = in.nextInt();
        while(coordinates[0] < 1 || coordinates[0] > 10) {
            System.out.println("Out of range, please set again.");
            coordinates[0] = in.nextInt();
        } 
        
        System.out.println("Set y:");
        coordinates[1] = in.nextInt();
        while(coordinates[1] < 1 || coordinates[1] > 10) {
            System.out.println("Out of range, please set again.");
            coordinates[1] = in.nextInt();
        }
        
        return coordinates;
    }
    
    public boolean hitShip(Board board) {
        int[] coor = setCoordinates();
     
        while(board.getBoard()[coor[0] - 1][coor[1] - 1].equals("M") ||
                board.getBoard()[coor[0] - 1][coor[1] - 1].equals("X")) {
            System.out.println("Symbol X or M, Set coordinates again");
            coor = setCoordinates();
        }
        if(board.getBoard()[coor[0] - 1][coor[1] - 1].equals("-")) {
            board.setFieldBoard("X", coor[0] - 1, coor[1] - 1);
            System.out.println("-----HIT-----");
            return true;
        }
        board.setFieldBoard("M", coor[0] - 1, coor[1] - 1);
        System.out.println("-----MISS-----");
        return false;
    }
}
